/* 
 * 图片上传 2014.4.5
 */

/* 初始化上传插件 */
$("#upload_picture").uploadify({
    "height": 30,
    "swf": swf_url,
    "fileObjName": "download",
    "buttonText": "上传图片",
    "uploader": uploader_url,
    "width": 120,
    'removeTimeout': 1,
    'fileTypeExts': '*.jpg; *.png; *.gif;',
    "onUploadSuccess": uploadPicture,
    'onFallback': function() {
        alert('未检测到兼容版本的Flash.');
    }
});
function uploadPicture(file, data) {
    var data = $.parseJSON(data);
    var src = '';
    if (data.status) {
        src = data.url || root_url + data.path;
        $("#pdf_toppic").val(src);
        $("#pdf_toppic").parent().find('.upload-img-box').html(
                '<div class="upload-pre-item"><img src="' + src + '"/></div>'
                );
    } else {
        updateAlert(data.info);
        setTimeout(function() {
            $('#top-alert').find('button').click();
            $(that).removeClass('disabled').prop('disabled', false);
        }, 1500);
    }
}

$("#upload_pdf_bottom_picture").uploadify({
    "height": 30,
    "swf": swf_url,
    "fileObjName": "download",
    "buttonText": "上传图片",
    "uploader": uploader_url,
    "width": 120,
    'removeTimeout': 1,
    'fileTypeExts': '*.jpg; *.png; *.gif;',
    "onUploadSuccess": uploadPictureBottom,
    'onFallback': function() {
        alert('未检测到兼容版本的Flash.');
    }
});
function uploadPictureBottom(file, data) {
    var data = $.parseJSON(data);
    var src = '';
    if (data.status) {
        src = data.url || root_url + data.path;
        $("#pdf_bottompic").val(src);        
        $("#pdf_bottompic").parent().find('.upload-img-box-bottom').html(
                '<div class="upload-pre-item-pdf-bottom"><img src="' + src + '"/></div>'
                );
    } else {
        updateAlert(data.info);
        setTimeout(function() {
            $('#top-alert').find('button').click();
            $(that).removeClass('disabled').prop('disabled', false);
        }, 1500);
    }
}

$("#upload_watermark_img").uploadify({
    "height": 30,
    "swf": swf_url,
    "fileObjName": "download",
    "buttonText": "上传水印图片",
    "uploader": uploader_url,
    "width": 120,
    'removeTimeout': 1,
    'fileTypeExts': '*.jpg; *.png; *.gif;',
    "onUploadSuccess": uploadWaterMarkImg,
    'onFallback': function() {
        alert('未检测到兼容版本的Flash.');
    }
});
function uploadWaterMarkImg(file, data) {
    var data = $.parseJSON(data);
    var src = '';
    if (data.status) {
        src = data.url || root_url + data.path;
        $("#watermark_img").val(src);        
        $("#watermark_img").parent().find('.upload-watermark-img-box').html(
                '<div class="upload-pre-item-pdf-bottom"><img src="' + src + '"/></div>'
                );
    } else {
        updateAlert(data.info);
        setTimeout(function() {
            $('#top-alert').find('button').click();
            $(that).removeClass('disabled').prop('disabled', false);
        }, 1500);
    }
}


